<template>
  <div class="citySelect">
    <van-tree-select
      @click-nav="handleItemNav"
      :items="items"
      :active-id.sync="activeId"
      :main-active-index.sync="activeIndex"
      @click-item="handleItem"
    />
  </div>
</template>

<style lang="scss" scoped>
.citySelect {
  height: 100vh;
  .van-tree-select {
    height: 100vh !important;
    font-size: 18px;
  }
  .van-tree-select__item--active {
    color: #1989fa;
  }
  .van-sidebar-item {
    font-size: 18px;
  }
  .van-sidebar-item--select::before {
    background-color: #1989fa;
  }
}
</style>


<script>
import { getDatalistForTree, getuserRelManyBiz, judgeIsExist } from '@/utils/api'
export default {
  data() {
    return {
      getWGCityOpenDataView:"",
      items: [
        {
          // 导航名称
          text: '惠州市',
          // 导航名称右上角徽标，2.5.6 版本开始支持
          // badge: 3,
          // 是否在导航名称右上角显示小红点
          // dot: true,
          // 导航节点额外类名
          className: 'my-class',
          // 该导航下所有的可选项
          children: [],
        },
        {
          text: '  ',
        },
      ],
      activeId: 0,
      activeIndex: 0,
    }
  },
  methods: {
    // logout() {
    //   this.$swal({
    //     text: '你确定要退出吗?',
    //     confirmButtonText: '退出',
    //   }).then((res) => {
    //     if (res.value) {
    //       this.$store.dispatch('logout')
    //     }
    //   })
    // },
    getCityOpenDataView: async function (data) {
      this.items[0].children = []
      const res = await getDatalistForTree(data)
      console.log(window.sessionStorage.getItem('cityDuo'),'xioahe')
      res.data.data.forEach((item, index) => {
        if (window.sessionStorage.getItem('cityDuo')) {
          window.sessionStorage
            .getItem('cityDuo')
            .split(',')
            .forEach((it) => {
              if (item.citycode == it) {
                console.log(item.citycode , it)
                var obj = {
                  text: item.cityname,
                  id: index + 1,
                  dot: true,
                  citycode: item.citycode,
                }
                this.items[0].children.push(obj)
              }
              //else {
              //   var obj = {
              //     text: item.cityname,
              //     id: index + 1,
              //     citycode: item.citycode,
              //   }
              // }
            })
        } else {
          var obj = {
            text: item.cityname,
            id: index + 1,
            citycode: item.citycode,
          }
          this.items[0].children.push(obj)
        }
      })
      let newObj = {
        text: '临安区',
        id: 12,
        citycode: '330112000000',
      }
      this.items[0].children.push(newObj)
    },
    wgcitycode:async  function(){
      this.items[0].children = []
      this.getWGCityOpenDataView.cityList.forEach((items,index)=>{
        let newObj = {
          text: items.cityName,
          id: index+1,
          citycode: items.cityCode,
        }
        this.items[0].children.push(newObj)
      })

    },
    handleItemNav() {
      console.log('dsfheuih')
      this.getCityOpenDataView('330000000000')
    },
     handleItem(data) {
      debugger
       //危改鉴定公司跳转
       if(this.$route.query&&this.$route.query.iswgdb=="true"){
         this.$router.push({
           path: '/MyAgentSNew',
           query:{data:JSON.stringify(this.getWGCityOpenDataView),city:JSON.stringify(data)},
         })
       }
      //判断当前地市是否注册了账号
      // let formData = JSON.parse(window.localStorage.getItem('FRUSER'))
      // const res = await judgeIsExist(data.citycode, (formData&&formData.uniscid)||'913301857471537181')
        // window.localStorage.setItem('citycode', data.citycode)
        // this.$router.push({
        //   path: '/ZLJIndex',
        // })
    },
  },
  mounted() {
    debugger
    if(this.$route.query&&this.$route.query.iswgdb=="true"){
     this.getWGCityOpenDataView=JSON.parse(this.$route.query.data);
      this.wgcitycode();
    }else{
      this.getCityOpenDataView('330000000000')
    }

  },
}
</script>
